	<script type="text/javascript" src="js/jquery-1.11.0.min.js"></script>
	<script type="text/javascript" src="js/lqjs.js"></script>	
	<script type="text/javascript" src="js/jquerysession.js"></script>
	<!--[if (gte IE 6)&(lte IE 10)]>
	  <link href="css/lqcssie.css" rel="stylesheet" type="text/css">
	  <link href="css/lqpublicie.css" rel="stylesheet" type="text/css">
	<![endif]-->
							<div class="rightcontent">
								<!-- 页面导航 -->
								<div class="righttopnav">
									<a class="index">首页></a><a>管理员管理</a>
								</div>
								<!-- 操作区 -->
								<div class="caozuodiv">
									<input class="searchinpu" type="text" name="" placeholder="用户名">
									<a class="originborbtn searchop">查询</a>
									<a class="originbtn addop">+新增</a>
								</div>

								<!-- 数据table -->
								<div class="contenttable">
									
									<table id="table01" class="table01">
										<colgroup>
										 <col class="item-list-col0">
										 <col class="item-list-col1">
										 <col class="item-list-col2">
										 <col class="item-list-col3">
										 <col class="item-list-col4">
										 <col class="item-list-col5">
										 <col class="item-list-col6">
										 </colgroup>
										<tr>
											<th>用户ID</th>
											<th>用户名称</th>
											<th>登录类型</th>
											<th>登录类型</th>
											<th>状态</th>
											<th>创建时间</th>
											<th>操作</th>
										</tr>
																				
									</table>
								</div>

								<!-- 翻页 -->
								<div class="pages">
									
								</div>
							</div>
								<!-- 新建操作员 -->
						<div class="zhezhaodiv"></div>
						<div class="editordiv">
							<!-- 页面导航 -->
								<div class="righttopnav">
									新增
								</div>

								<!-- 数据table -->
								<div class="contenttable">
									
									<div id="table01">										
										<div class="table_user">
											<label class="add_lable">用户名称</label>
											<input class="table_inp" id="loginName" type="text" name=""/>
										</div>					
										<div class="table_user">
											<label class="add_lable">用户密码</label>
											<input class="table_inp" id="password" type="text" name=""/>
										</div>				
										<div class="table_user">
											<label class="add_lable">设置权限</label>	
											<label class="labelp"><input type="radio" name="abcd" value="4" checked><i>✓</i>系统管理员</label>	
											<label class="labelp"><input type="radio" name="abcd" value="3"><i>✓</i>运维</label>
											<label class="labelp"><input type="radio" name="abcd" value="2"><i>✓</i>客服</label> 
											<label class="labelp"><input type="radio" name="abcd" value="1"><i>✓</i>管理员</label>
										</div>	
										<div class="table_user">
											<label class="add_lable">状态</label>	
											<label class="labelp"><input type="radio" name="abc" value="Y"><i>✓</i>启用</label>
											<label class="labelp"><input type="radio" name="abc" value="N" checked><i>✓</i>停止</label><br>  
	
										</div>	
										<div class="btns">
											<a class="originbtn adduserbtn">确定</a>
											<a class="whitebtn backbtn">返回</a>
										</div>	
									</div>
								</div>
						</div>
		<!-- 	</div>
			
		</div> -->
<script type="text/javascript" src="js/jquerysession.js"></script>
<script type="text/javascript">
console.log('管理员管理');
 $(document).ready(function() {  
        // val()无参数是取值，有参数是设置  
        // 为了更好的兼容性，将下面的val()设置与input中的placeholder的值设置相同  
        $("input.searchinpu").val("请输入完整用户名");  
        textFill($('input.searchinpu'));  
    }); 

$(".navli").click(function(){
	$(this).addClass('select').siblings().removeClass('select');					
});
// var urank = $.session.get('rank');
//遮罩层弹窗							
zhezhao(ison);

//添加新数据
//新增
$(".addop").click(function(){
	if(ison){
		ison = false;
		zhezhao(ison);
	}else{
		ison = true;
		zhezhao(ison);
	}
	
})

//返回
$(".backbtn").click(function(){
	if(ison){
		if(ison){
		ison = false;
		zhezhao(ison);
	}else{
		ison = true;
		zhezhao(ison);
	}
	}
});
//确认
$(".adduserbtn").click(function(){
	console.log('确认');
	if(ison){
		if(ison){
		ison = false;
		zhezhao(ison);
	}else{
		ison = true;
		zhezhao(ison);
	}
	}
	//提交添加数据
	var loginName = $("#loginName").val();
	var password = $("#password").val();
	var addrank = $("input[name='abcd']:checked").val();
	var state = $("input[name='abc']:checked").val();
	if(loginName.length!= 0 && password.length!= 0 && addrank.length!= 0 &&state.length!= 0){
	$.ajax({
		type: "get",
		url: url+"manager/addManager",
		data:{
			'loginName': loginName,
			'password': password,
			'rank': urank,
			'state': state,
			'addrank': addrank,
		},
		success: function(data){
			if (data.code == '2000') {
				alert('添加成功');
				opuserinfo(newpage);
			}else{
				console.log('系统错误');
			}
		}
	});
	}else{
		console.log('请输入全部数据');
	}

});

// json 时间格式转化 1520305366000
 function timeStamp2String(time){
    var datetime = new Date();
    datetime.setTime(time);
    var year = datetime.getFullYear();
    var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
    var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
    var hour = datetime.getHours()< 10 ? "0" + datetime.getHours() : datetime.getHours();
    var minute = datetime.getMinutes()< 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
    var second = datetime.getSeconds()< 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
    return year + "-" + month + "-" + date;
};

				// 用户数据
				var id = 0;//序号
				var newpage = 0; //当前页面
				var pagesize = 5; //每页条数

				opuserinfo(newpage);//加载数据
				function opuserinfo(newpage){
				$.ajax({
					type: "get",
					url: url+"manager/showByPage",
					data:{
						'page': newpage,
						'pageSize': pagesize
					},
					success: function(data){
						var userinfo = data.data.content;
						var pageable = data.data.pageable; //用户翻页
						var totalElements = data.data.totalElements; //总条数
						var pageNumber = pageable.pageNumber;//当前第几页
						var totalPages = data.data.totalPages;//总页数
						if(data.code=='2000'){
							var userhtml = '<colgroup>'
										 +'<col class="item-list-col0">'
										 +'<col class="item-list-col1">'
										 +'<col class="item-list-col2">'
										 +'<col class="item-list-col3">'
										 +'<col class="item-list-col4">'
										 +'<col class="item-list-col5">'
										 +'<col class="item-list-col6">'
										 +'</colgroup>'
										+'<tr>'
											+'<th>用户ID</th>'
											+'<th>用户名称</th>'
											+'<th>登录类型</th>'
											+'<th>登录类型</th>'
											+'<th>状态</th>'
											+'<th>创建时间</th>'
											+'<th>操作</th>'
										+'</tr>';
							for(var i in userinfo){
								var usertime = timeStamp2String(parseInt(userinfo[i].createdDatetime));
								var usid = userinfo[i].sid;
								var ustate = userinfo[i].state;
								id++;
								if(ustate=='Y'){
									ustate = '已启用';
								}else{
									ustate = '禁用';
								}								
								userhtml += '<tr>'+
											'<td>'+id+'</td>'+
											'<td>'+userinfo[i].loginName+'</td>'+
											'<td>账号</td>'+
											'<td>账号</td>'+	
											'<td>'+ustate+'</td>'+
											'<td>'+usertime+'</td>'+
											'<td><a class="tab_editor"></a><a class="tab_del" sid="'+usid+'"></a></td>'+
											'</tr>';
							}

							$("#table01").html('');
							$("#table01").append(userhtml);
							console.log('数据成功加载');

							

							//翻页
							var pagehtml='';						
							var now = pageNumber+1;
							pagehtml = '<a class="pre"><</a>'
									+'<ul class="pagesul">'
										+'<li class="pagesnum thispage">'+now+'</li>'
										+'<li class="pagesnum">总共'+totalPages+'页</li>'
										+'<li class="pagesnum"><input class="pageinp" id="yema" type="number" oninput="checkNum(this.value)" placeholder="输入页码" value=""/></li>'
										+'<li class="pagesnum thispage tiaoz">跳转</li>'
									+'</ul>'
									+'<a class="next">></a>';
							$(".pages").html(pagehtml);

							//跳转页码
							$(".tiaoz").click(function(){
								var thispage = $(".pageinp").val(); //输入跳转的页码
								// newpage = parseInt(thispage-1);
								//输入页码不为空
								if(thispage.length!=0 && !isNaN(thispage)){
									console.log("当前输入页面"+thispage);
									if(totalPages+1>thispage>0){
										
										if(newpage == thispage-1){
											//如果是跳转当前页面,则不跳转，不刷新页面
											console.log('跳转当前页面');
											newpage = thispage-1;
											return false;
										}else{
											//跳转到输入页面
											id = (thispage-1)*pagesize;//跳转页面id起始
											newpage = thispage-1;
											opuserinfo(newpage);
										}
										
									}else{
										alert('请输入准确页码');
										$(".pageinp").val('');//清空搜索框
									}
									
								}
								
							});
							//上一页
							$(".pre").click(function(){
								console.log(newpage);
								// var thispage = $(".pageinp").val(); //输入跳转的页码
								// newpage = parseInt(thispage-1);
								if(newpage>0){
									//当前页面需要大于0 ，小于总页数
									//如果当前条数少于每页条数时，即最后一页
									console.log('userinfo.length'+userinfo.length);
									if(userinfo.length<pagesize){
										id = id-userinfo.length-pagesize;
										console.log('id==' +id);
										opuserinfo(newpage-1);
									}else if(userinfo.length==pagesize){
										id = id - pagesize*2;
										opuserinfo(newpage-1);
									}
								}else{
									alert('没有上一页了');
								}								
							})
							//下一页
							$(".next").click(function(){
								console.log(newpage);
								// newpage = parseInt($(".thispage").html()-1);
								if(totalPages-1>newpage){
									//当前页面需要小于总页数
									opuserinfo(newpage+1);
								}else{
									alert('没有下一页了');
								}
							})
							//编辑用户信息
							$(".tab_editor").click(function(){
								console.log('123');
								if(ison){
									ison = false;
									zhezhao(ison);
								}else{
									ison = true;
									zhezhao(ison);
								}							
							});

							// 删除事件
							$(".tab_del").click(function(){
								console.log('sid'+$(this).attr('sid'));
								console.log(urank);
								$.ajax({
									type: "post",
									url: url+"manager/removeManager",
									data:{
										'sid': $(this).attr('sid'),
										'rank': urank
									},
									success: function(data){
										if (data.code == '2000') {
											alert('删除成功');
											opuserinfo(newpage);
										}else{
											console.log('删除失败');
										}
									}
								});
							});
							
						}else{
							alert('系统错误');
						}
					}
			})
			};



			//搜索
			$(".searchop").click(function(){
				console.log('搜索');
				var searchname = $(".searchinpu").val();
				$.ajax({
					type: "get",
					url: url+"manager/queryByName",
					data:{
						'name': searchname
					},
					success: function(data){
						console.log(data);						
						if(data.code=='2000'){
							var userinfo = data.data.manager;
							var userhtml = '<colgroup>'
										 +'<col class="item-list-col0">'
										 +'<col class="item-list-col1">'
										 +'<col class="item-list-col2">'
										 +'<col class="item-list-col3">'
										 +'<col class="item-list-col4">'
										 +'<col class="item-list-col5">'
										 +'<col class="item-list-col6">'
										 +'</colgroup>'
										+'<tr>'
											+'<th>用户ID</th>'
											+'<th>用户名称</th>'
											+'<th>登录类型</th>'
											+'<th>登录类型</th>'
											+'<th>状态</th>'
											+'<th>创建时间</th>'
											+'<th>操作</th>'
										+'</tr>';
							// for(var i in userinfo){
								var usertime = timeStamp2String(parseInt(userinfo.createdDatetime));
								var usid = userinfo.sid;
								var ustate = userinfo.state
								if(ustate=='Y'){
									ustate = '已启用'
								}else{
									ustate = '禁用'
								}
								userhtml += '<tr>'+
											'<td></td>'+
											'<td>'+userinfo.loginName+'</td>'+
											'<td>手机号</td>'+
											'<td>手机号</td>'+	
											'<td>启用</td>'+
											'<td>'+usertime+'</td>'+
											'<td><a class="tab_editor"></a><a class="tab_del" sid="'+usid+'"></a></td>'+
											'</tr>';
							// }
							$("#table01").html('');
							$("#table01").append(userhtml);
							console.log('数据搜索成功');
						}else if(data.code=='5000'){
							alert('没有此条数据');
						}else{
							console.log('系统错误');
						}
					}
				})
			});			
			
</script>
